2 ==============================================================================
4 This file is part of the JUCE library - "Jules' Utility Class Extensions"
5 Copyright 2004-11 by Raw Material Software Ltd.
7 ------------------------------------------------------------------------------
9 JUCE can be redistributed and/or modified under the terms of the GNU General
10 Public License (Version 2), as published by the Free Software Foundation.
11 A copy of the license is included in the JUCE distribution, or can be found
12 online at www.gnu.org/licenses.
14 JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
15 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
16 A PARTICULAR PURPOSE. See the GNU General Public License for more details.
18 ------------------------------------------------------------------------------
20 To release a closed-source product which uses JUCE, commercial licenses are
21 available: visit www.rawmaterialsoftware.com/juce for more information.
23 ==============================================================================
26 #include "../jucer_Headers.h"
27 #include "jucer_TestComponent.h"
28 #include "../model/jucer_ObjectTypes.h"
31 static Array
<TestComponent
*> testComponents
;
33 //==============================================================================
34 TestComponent::TestComponent (JucerDocument
* const ownerDocument_
,
35 JucerDocument
* const loadedDocument_
,
36 const bool alwaysFillBackground_
)
37 : ownerDocument (ownerDocument_
),
38 loadedDocument (loadedDocument_
),
39 alwaysFillBackground (alwaysFillBackground_
)
43 testComponents
.add (this);
46 TestComponent::~TestComponent()
48 testComponents
.removeValue (this);
50 delete loadedDocument
;
53 //==============================================================================
54 void TestComponent::reloadAll()
56 for (int i
= testComponents
.size(); --i
>= 0;)
57 testComponents
.getUnchecked(i
)->reload();
60 void TestComponent::reload()
62 if (findFile().exists() && lastModificationTime
!= findFile().getLastModificationTime())
63 setFilename (filename
);
66 //==============================================================================
67 static StringArray recursiveFiles
;
69 const File
TestComponent::findFile() const
71 if (filename
.isEmpty())
72 return File::nonexistent
;
74 if (ownerDocument
!= 0)
75 return ownerDocument
->getFile().getSiblingFile (filename
);
77 return File::getCurrentWorkingDirectory().getChildFile (filename
);
80 void TestComponent::setFilename (const String
& newName
)
84 if (newName
.isNotEmpty())
86 if (ownerDocument
!= 0)
87 newFile
= ownerDocument
->getFile().getSiblingFile (newName
);
89 newFile
= File::getCurrentWorkingDirectory().getChildFile (newName
);
92 if (! recursiveFiles
.contains (newFile
.getFullPathName()))
94 recursiveFiles
.add (newFile
.getFullPathName());
96 deleteAndZero (loadedDocument
);
99 lastModificationTime
= findFile().getLastModificationTime();
101 loadedDocument
= ObjectTypes::loadDocumentFromFile (findFile(), false);
106 recursiveFiles
.remove (recursiveFiles
.size() - 1);
110 void TestComponent::setConstructorParams (const String
& newParams
)
112 constructorParams
= newParams
;
115 void TestComponent::updateContents()
120 if (loadedDocument
!= 0)
122 addAndMakeVisible (loadedDocument
->createTestComponent (alwaysFillBackground
));
127 void TestComponent::setToInitialSize()
129 if (loadedDocument
!= 0)
131 setSize (loadedDocument
->getInitialWidth(),
132 loadedDocument
->getInitialHeight());
140 //==============================================================================
141 void TestComponent::paint (Graphics
& g
)
143 if (loadedDocument
== 0)
145 g
.fillAll (Colours::white
.withAlpha (0.25f
));
147 g
.setColour (Colours::black
.withAlpha (0.5f
));
148 g
.drawRect (0, 0, getWidth(), getHeight());
149 g
.drawLine (0.0f
, 0.0f
, (float) getWidth(), (float) getHeight());
150 g
.drawLine (0.0f
, (float) getHeight(), (float) getWidth(), 0.0f
);
153 g
.drawText ("Jucer Component",
154 0, 0, getWidth(), getHeight() / 2,
155 Justification::centred
, true);
156 g
.drawText ("(no file loaded)",
157 0, getHeight() / 2, getWidth(), getHeight() / 2,
158 Justification::centred
, true);
162 void TestComponent::resized()
164 Component
* const c
= getChildComponent (0);
168 setOpaque (c
->isOpaque());
169 c
->setBounds (0, 0, getWidth(), getHeight());
173 //==============================================================================
174 void TestComponent::showInDialogBox (JucerDocument
& document
)
176 TooltipWindow
tooltipWindow (0, 400);
178 TestComponent
testComp (0, document
.createCopy(), true);
180 DialogWindow::showModalDialog ("Testing: " + document
.getClassName(),